package rhc.singleNodeSpider.execute;

import java.util.HashMap;
import java.util.Map;

import rhc.discribute.node.commander.Commander;
import rhc.singleNodeSpider.BasicComponent;
import rhc.singleNodeSpider.spiderManage.SpiderManage;
import rhc.singleNodeSpider.spiderManage.impl.SpiderManageImpl;
import rhc.taskSchedule.commander.TaskScheduleCommander;
import rhc.taskSchedule.taskSignalCall.CustomCall;

/**单节点爬虫执行器
 * @author rhc
 *
 */
public class SingleNodeSpiderExecuter extends BasicComponent {

	/**
	 * 分布式节点
	 */
	private Commander distributeNodeCommander;
	
	/**
	 * 单节点爬虫管理器
	 */
	private SpiderManage spiderManage;
	
	/**
	 * 任务调度管理器
	 */
	private TaskScheduleCommander taskScheduleCommander;
	
	private String spiderTaskTypeName="spider_task";
	
	/**
	 * 任务id对应的主动调用任务调度器的的回调
	 */
	private Map<String,CustomCall> taskId_customCall=new HashMap<String,CustomCall>();
	
	/**
	 * 注册到任务调度器的通知
	 */
	private SpiderTaskNoticeCustom spiderTaskNoticeCustom;
	
	/**
	 * 管理任务调度器的回调
	 */
	private CustomCallTaskScheduleManage customCallTaskScheduleManage;
	
	public SingleNodeSpiderExecuter(Commander distributeNodeCommander) throws Exception{
		this.distributeNodeCommander=distributeNodeCommander;
		spiderManage=new SpiderManageImpl();
		
		taskScheduleCommander=new TaskScheduleCommander(distributeNodeCommander);
		taskScheduleCommander.registerNoticeCustom(spiderTaskTypeName, spiderTaskNoticeCustom);
		
		customCallTaskScheduleManage=new CustomCallTaskScheduleManage(spiderManage);
		
		spiderTaskNoticeCustom=new SpiderTaskNoticeCustom(this);
	}

	public SpiderManage getSpiderManage() {
		return spiderManage;
	}

	public void setSpiderManage(SpiderManage spiderManage) {
		this.spiderManage = spiderManage;
	}

	public CustomCallTaskScheduleManage getCustomCallTaskScheduleManage() {
		return customCallTaskScheduleManage;
	}

	public void setCustomCallTaskScheduleManage(CustomCallTaskScheduleManage customCallTaskScheduleManage) {
		this.customCallTaskScheduleManage = customCallTaskScheduleManage;
	}
	
}
